package net.scdx.hotel.service.impl;

import net.scdx.hotel.entity.Room;
import net.scdx.hotel.mapper.RoomMapper;
import net.scdx.hotel.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoomServiceImpl implements RoomService {

    @Autowired
    private RoomMapper roomMapper;

    @Override
    public List<Room> queryRoomsByHotelId(Integer hotelId) throws Exception {
        List<Room> rooms = roomMapper.selectByHotelId(hotelId);

        return rooms;
    }

    @Override
    public Room queryRoomByRoomId(Integer roomId) throws Exception{
        Room room=roomMapper.selectByPrimaryKey(roomId);

        return room;
    }

    @Override
    public boolean modifyRoomAmount(Integer roomId,Integer res) throws Exception{
        int effectedNum = roomMapper.updateAmountByPrimaryKey(roomId,res);
        if (effectedNum > 0)
            return true;
        return false;
    }

    @Override
    public boolean modifyIsempty(Integer roomId) throws Exception{
        int effectedNum = roomMapper.updateIsemptyByPrimaryKey(roomId);
        if (effectedNum > 0)
            return true;
        return false;
    }

}
